/************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     function_drv.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-01
  * @brief    
 *************************************************************************/

#ifndef _FUNCTION_DRV_H
#define _FUNCTION_DRV_H

#include "type.h"
#include "dma.h"
//#include "spi_drv.h"

/*
-- Backlight --
-- Buzzer --
-- Wav --
-- SD --
*/
extern uint8_t g_encoder_enable;
extern uint8_t g_byteswap_enable;
extern uint8_t g_qspipanel_enable;
/*------------------------------------macro definition init---------------------------------------------*/
void LT_definition_Init(void);

//------------------------------------------ Backlight ------------------------------
void LCD_BL_Init(uint16_t PWM_Width);
void LT_BacklightClose(void);
void LT_BacklightOpen(void);
void LT_BacklightSet(uint16_t PWM_Width);

//extern uint8_t Auto_Backlight; // Automatic backlight
//extern uint8_t Backlight_Off;
//extern uint8_t Backlight_On;
extern uint16_t gDutyBuf[];

//------------------------------------------ Buzzer ------------------------------
void touch_buzzer_init(void);
void touch_buzzer(void);
void touch_buzzer_close(void);

extern uint8_t buzzer_start;

//------------------------------------------ WAV ------------------------------
void WAV_amplifier_EN(void);
void WAV_amplifier_DIS(void);

//------------------------------------------ Encoder ------------------------------
#define PINA                ((EPORT1->EPPDR>>6)&0x01)
#define PINB                ((EPORT1->EPPDR>>0)&0x01)
#define Read_Encoder_key	((EPORT0->EPPDR>>7)&0x01)
#define EncType 	1 		//0 is a certain bit one pulse, 1 is two positioning one pulse

typedef enum
{
    SINGLECLICK = 0,
    SHORTCLICK,
    DOUBLECLICK,
    LONGCLICK,
	
    ROTATELEFT = 0x0A,
    ROTATERIGHT,
}ENCODER_KEY_;

void Encoder_Init(void);

//------------------------------------------ SD ------------------------------
#define SD_CS_SET
#define SD_CS_RESET
#define Speed_High   0
#define Speed_Low    0

void SD_SPIx_Initial(void);
uint16_t SD_SPIx_ReadWriteByte(uint16_t TxData);
void SD_SPIx_SetSpeed(uint16_t speed);
void SD_SPIx_DMA_Tran(uint8_t *Tx_Addr, uint8_t *Rx_Addr, uint32_t length);
void SD_SPIx_DMA_Wait(void);
void SD_SPIx_ReadData_EDMA(uint8_t *Tx_Addr, uint32_t length);
void SD_SPI_close(void);
void SD_IN_Enable(void);    // enable SD detection
uint8_t SD_detection(void); // SD detection

//------------------------------------------   ------------------------------

#endif /* _FUNCTION_DRV_H */
